import {RouteRecordRaw} from 'vue-router';

const backendFiles = import.meta.glob('../router/modules/*.ts', { eager: true })
const filesBackendModules: any[] = Object.values(backendFiles)
const routeBackendModules = filesBackendModules.reduce((previousRoutes, currentModule) => {
    return previousRoutes.concat(currentModule.default)
}, [] as any[])

const routes: Array<RouteRecordRaw> = [
    {
        path: '/back',
        redirect: '/back/home',
        component: () => import('../views/layout/index.vue'),
        children: routeBackendModules
    },
    {
        path: '/login',
        component: () => import('../views/common/Login.vue')
    },
    // 404
    {
        path: '/:pathMatch(.*)*',
        component: () => import('../views/common/404.vue')
    }
];

export default routes;
